package ru.elteam.ejb.logic;

import org.apache.commons.lang3.time.DateUtils;
import ru.elteam.ejb.entities.User;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Nikita.Brazhnikov
 * Date: 10/5/12
 * Time: 9:35 AM
 * To change this template use File | Settings | File Templates.
 */
@Stateless
public class UserMangementBean {

	@PersistenceContext(unitName = "server_unit")
	private EntityManager em;

	public Integer register(String username, String password, String email) {
		User newUser = new User();
		newUser.setUsername(username);
		newUser.setPassword(password);
		em.persist(newUser);
		return newUser.getId();
	}

	public User getUser(String name) {
		User user = new User();
		user.setUsername(name);
		user.setPassword("123");
		user.setLastLoginDate(DateUtils.addDays(new Date(), -1));
		user.setRegisterDate(DateUtils.addMonths(new Date(), -4));
		return user;
	}
}
